home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Flock 1.0 beta / flock-1.0RC3.en-US.win32.exe / flock / components / flockError.js < prev    next >
Text File  |  2007-10-18  |  4KB  |  141 lines

  1. // BEGIN FLOCK GPL
  2. // 
  3. // Copyright Flock Inc. 2005-2007
  4. // http://flock.com
  5. // 
  6. // This file may be used under the terms of of the
  7. // GNU General Public License Version 2 or later (the "GPL"),
  8. // http://www.gnu.org/licenses/gpl.html
  9. // 
  10. // Software distributed under the License is distributed on an "AS IS" basis,
  11. // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. // for the specific language governing rights and limitations under the
  13. // License.
  14. // 
  15. // END FLOCK GPL
  16.  
  17. const CC = Components.classes;
  18. const CI = Components.interfaces;
  19. const CR = Components.results;
  20.  
  21. const FLOCK_ERROR_CID = Components.ID("{2DB3FC08-E5F8-11DA-8ACF-C9DED1573834}");
  22. const FLOCK_ERROR_CONTRACTID = "@flock.com/error;1";
  23. const FLOCK_ERROR_IID = CI.flockIError;
  24.  
  25. const FLOCK_LOGGER_CONTRACTID = "@flock.com/logger;1";
  26. const STRING_BUNDLE_CONTRACTID = "@mozilla.org/intl/stringbundle;1";
  27. const STRING_BUNDLE_IID = CI.nsIStringBundleService;
  28. const STRING_BUNDLE_URL = "chrome://flock/locale/common/flockErrors.properties";
  29.  
  30. const STRING_KEY_PREFIX = "flock.service.errorCode_";
  31. // Alternate string when we want to substitute in a service name or similar.
  32. const STRING_KEY_SUBST_SUFFIX = ".subst";
  33.  
  34. function flockError() {
  35.   this._logger = CC[FLOCK_LOGGER_CONTRACTID].createInstance(CI.flockILogger);
  36.   this._logger.init("flockerror");
  37. }
  38.  
  39. flockError.prototype = {
  40.   errorCode: 0,
  41.   serviceErrorCode: "",
  42.   serviceErrorString: "",
  43.   serviceName: "",
  44.   QueryInterface: function QueryInterface(aIid) {
  45.     if (!aIid.equals(CI.nsISupports) &&
  46.         !aIid.equals(FLOCK_ERROR_IID))
  47.     {
  48.       throw CR.NS_ERROR_NO_INTERFACE;
  49.     }
  50.     return this;
  51.   }
  52. };
  53.  
  54. flockError.prototype.__defineGetter__("errorString",
  55.                                       function () {
  56.                                         return this.lookUp(this.errorCode,
  57.                                                            this.serviceName);
  58.                                       });
  59.  
  60. //////////////////////////////////////////////////////////////////////////////
  61. // internal methods
  62. //////////////////////////////////////////////////////////////////////////////
  63.  
  64. flockError.prototype.lookUp =
  65. function flockError_lookUp(aErrorCode, aServiceName)
  66. {
  67.   var msg;
  68.   try {
  69.     this._logger.debug("aErrorcode is " + aErrorCode);
  70.     var stringKey = STRING_KEY_PREFIX + aErrorCode;
  71.     if (aServiceName != "") {
  72.       msg = this.mStringBundle
  73.                 .formatStringFromName(stringKey + STRING_KEY_SUBST_SUFFIX,
  74.                                       [aServiceName], 1); // 1: array length
  75.     } else {
  76.       msg = this.mStringBundle.GetStringFromName(stringKey);
  77.     }
  78.     this._logger.debug(msg);
  79.   } catch (ex1) {
  80.     this._logger.error(ex1);
  81.   }
  82.   return msg;
  83. };
  84.  
  85. flockError.prototype.mStringBundle = CC[STRING_BUNDLE_CONTRACTID].
  86.                                      getService(STRING_BUNDLE_IID).
  87.                                      createBundle(STRING_BUNDLE_URL);
  88.  
  89. //////////////////////////////////////////////////////////////////////////////
  90. // Factory Definitions
  91. //////////////////////////////////////////////////////////////////////////////
  92. var flockErrorModule = {
  93.   registerSelf: function registerSelf(aCompMgr, aFileSpec, aLocation, aType)
  94.   {
  95.     aCompMgr = aCompMgr.QueryInterface(CI.nsIComponentRegistrar);
  96.     aCompMgr.registerFactoryLocation(FLOCK_ERROR_CID,
  97.                                      "flockError JS component",
  98.                                      FLOCK_ERROR_CONTRACTID,
  99.                                      aFileSpec,
  100.                                      aLocation,
  101.                                      aType);
  102.   },
  103.  
  104.   getClassObject: function getClassObject(aCompMgr, aCid, aIid)
  105.   {
  106.     if (!aCid.equals(FLOCK_ERROR_CID)) {
  107.       throw CR.NS_ERROR_NO_INTERFACE;
  108.     }
  109.     if (!aIid.equals(CI.nsIFactory)) {
  110.       throw CR.NS_ERROR_NOT_IMPLEMENTED;
  111.     }
  112.     return flockErrorFactory;
  113.   },
  114.  
  115.   canUnload: function canUnload(aCompMgr)
  116.   {
  117.     return true;
  118.   }
  119. };
  120.  
  121. var flockErrorFactory = {
  122.   createInstance: function createInstance(aOuter, aIid)
  123.   {
  124.     if (aOuter != null) {
  125.       throw CR.NS_ERROR_NO_AGGREGATION;
  126.     }
  127.     if (!aIid.equals(FLOCK_ERROR_IID) &&
  128.         !aIid.equals(CI.nsISupports))
  129.     {
  130.       throw CR.NS_ERROR_INVALID_ARG;
  131.     }
  132.     return new flockError();
  133.   }
  134. }
  135.  
  136. // module initialisation
  137. function NSGetModule(aComMgr, aFileSpec)
  138. {
  139.   return flockErrorModule;
  140. }
  141.